//无重复字符的最长子串
//测试链接 https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/
public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        if(s.length() == 0){
            return 0;
        }
        int left = 0, right = 0;
        int len = 1;
        int n = s.length();
        int[] hash = new int[128];
        while(right < n){
            hash[s.charAt(right)]++; //进窗口

            while(hash[s.charAt(right)] > 1){  //判断是否重复
                hash[s.charAt(left)]--;
                left++;
            }
            right++;
            len = Math.max(len, right - left);
        }

        return len;
    }
}
